import { Request } from './axios-config';
// import { SetStroageItem, GetStroageItem } from '@/utils/storage-utils';
import { RUC_SERVICE, TS_STOCK } from './constant';

// 获取我的发文收文公文列表
export const DocList = async (data) => {
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/document/v1/document/list`,
    data
  }).then((res) => res);
};

// 获取公文表详情
export const DocDetail = async (id) => {
  return await Request({
    method: 'GET',
    url: `${RUC_SERVICE}/api/document/v1/document/detail/${id}`
  }).then((res) => res);
};

// 新增时发布公文
export const PublishDoc = async (data) => {
  let triScopeInfo = data?.triScopeInfo || [];
  data.triScope = triScopeInfo?.map((item) => item.value).join(',') || '';
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/document/v1/document/add/publish`,
    data
  }).then((res) => res);
};

// 删除公文
export const DeleteDoc = async (id) => {
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/document/v1/document/delete/${id}`
  }).then((res) => res);
};

// 新增公文时保存公文草稿
export const SaveDoc = async (data) => {
  let triScopeInfo = data?.triScopeInfo || [];
  data.triScope = triScopeInfo?.map((item) => item.value).join(',') || '';
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/document/v1/document/add/draft`,
    data
  }).then((res) => res);
};

// 修改公文草稿时点击发布
export const PublishEditDoc = async (data) => {
  let triScopeInfo = data?.triScopeInfo || [];
  data.triScope = triScopeInfo?.map((item) => item.value).join(',') || '';
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/document/v1/document/edit/publish`,
    data
  }).then((res) => res);
};

// 修改公文草稿时保存公文草稿
export const SaveEditDoc = async (data) => {
  let triScopeInfo = data?.triScopeInfo || [];
  data.triScope = triScopeInfo?.map((item) => item.value).join(',') || '';
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/document/v1/document/edit/draft`,
    data
  }).then((res) => res);
};

// 获取我负责的公文事项列表
export const MyMatterList = async (data) => {
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/rucMatter/v1/rucMatter/my/list`,
    data
  }).then((res) => res);
};

// 获取授权我的公文事项列表
export const AllowMatterList = async (data) => {
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/rucMatter/v1/rucMatter/allow/list`,
    data
  }).then((res) => res);
};

// 获取业务草稿表列表
export const GetDraftList = async (data) => {
  return await Request({
    method: 'POST',
    // url: `${TS_STOCK}/api/bizDraft/v1/bizDraft/list`,
    url: `${TS_STOCK}/stockReceiveApply/page`,
    data
  }).then((res) => res);
};

// 获取公文事项表详情
export const GetMatterDetail = async (id) => {
  return await Request({
    method: 'GET',
    url: `${RUC_SERVICE}/api/rucMatter/v1/rucMatter/detail/${id}`
  }).then((res) => res);
};

// 修改公文事项查阅人
export const EditMatterUserList = async (data) => {
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/rucMatter/v1/rucMatter/user/edit`,
    data
  }).then((res) => res);
};

// 修改公文表-修改抄送人
export const EditDocumentCcUserList = async (data) => {
  return await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/api/document/v1/document/edit/users`,
    data
  }).then((res) => res);
};
